package com.foreknow.demo16;

/**
 * 100张票，分四个窗口卖完
 */
public class Ticket extends Thread {
    private static int tickets = 100;
    @Override
    public void run() {
        while (true){
            synchronized (Ticket.class){
                tickets--;
                if(tickets<=0){
                    break;
                }
                try {
                    Thread.sleep(60);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(getName()+": 这是第"+tickets+"号票卖出");
            }
        }
    }
}
